package business.optionForm_Evt;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import service.Service;

public class Statics_Evt 
{
    private JDialog dlg;
    Service ser = new Service();
    public Statics_Evt (JDialog dlg) 
    {
        this.dlg = dlg;
    }
    
    public void setTextComponent(JLabel lbrMaxLength, JLabel lbrBestWord, JLabel lbrMaxPoint, JLabel lbrWpm, JLabel lbrTotalTime, JLabel lbrAvgLength, JLabel lbrWordFound, JLabel lbrMaxLevel, JLabel lbrHighScore)
    {
    	String[] list = ser.gameStatics();
    	
        lbrMaxLength.setText(list[0] + "");
        lbrBestWord.setText(list[1] + "");
        lbrMaxPoint.setText(list[2] + "");
        lbrWpm.setText(list[3] + "");
        lbrTotalTime.setText(ser.timeStaticsFormat(Integer.parseInt(list[4])) + "s");
        lbrAvgLength.setText(list[5] + "");
        lbrWordFound.setText(list[6] + "");
        lbrMaxLevel.setText(list[7] + "");
        lbrHighScore.setText(ser.highScore()+"");
    }
    /**
     * Event of OK button
     */
    public void btClose_Evt()
    {
        dlg.setVisible(false);
    }
    
    /**
     * This will reset your static to default. and update it into file
     * @param lbrMaxLength
     * @param lbrAvgLength
     * @param lbrBestWord
     * @param lbrWpm
     * @param lbrTotalTime
     */
    public void btClear_Evt(JLabel lbrMaxLength, JLabel lbrBestWord, JLabel lbrMaxPoint, JLabel lbrWpm, JLabel lbrTotalTime, JLabel lbrAvgLength, JLabel lbrWordFound, JLabel lbrMaxLevel, JLabel lbrHighScore)
    {
        int confirm = JOptionPane.showConfirmDialog(null, "Are you sure you want to clear all your statics?", "Message", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

        if (confirm == JOptionPane.YES_OPTION) {
            
            lbrMaxLength.setText(0 + "");
            lbrBestWord.setText("no");
            lbrMaxPoint.setText(0 + "");
            lbrWpm.setText(0 + "");
            lbrTotalTime.setText(ser.timeStaticsFormat(0));
            lbrAvgLength.setText(0 + "");
            lbrWordFound.setText(0 + "");
            lbrMaxLevel.setText(0 + "");
            lbrHighScore.setText(0+"");
            ser.updateGameStatics(0, "no", 0, 0, 0, 0, 0, 0);
            ser.clearHighScore();
        }
    }
}

